package cn.skyclass.net
{
	import mx.collections.ArrayCollection;
	import mx.utils.ObjectUtil;
	
	/*
		尚未严格测试
	 * */
	 
	public class BuildUtil
	{		
		public static function buildList(o:Object, c:Class):ArrayCollection {
 			var result:ArrayCollection = o as ArrayCollection;
			var list:ArrayCollection = new ArrayCollection();
			if(result != null) {
				for(var i:uint = 0; i < result.length; ++ i) {
					list.addItem(buildObject(result.getItemAt(i), c));
				}
			}
			return list;
		}
			
		public static function buildObject(o:Object, c:Class):Object{
			var result:Object = new c();;
			
			var classInfo:Object = ObjectUtil.getClassInfo(o);
			for each(var i:String in classInfo["properties"]){
				try {
        			result[i] = o[i];
   				} catch(e:Error){}
    		}
			return result;
		}
	}
}